package xyz.app.logic;

import lombok.extern.slf4j.Slf4j;

import java.util.Optional;

@Slf4j
public enum PersistenceAction {
    KEEP, MERGE, NULLIFY, PERSIST, REPLACE, SAVE_COPY, UNDEFINED;

    void log(PersistenceLogic<?> logic) {

        var prop = logic.getInput();

        switch (this) {
            case SAVE_COPY -> log.info("SAVE COPY persistence proposition [{}]", prop.string());
            case KEEP -> log.info("KEEP persistence proposition [{}]", prop.string());
            case MERGE -> log.info("MERGE persistence proposition [{}]", prop.string());
            case NULLIFY -> Optional.ofNullable(prop).ifPresentOrElse(
                    e -> log.info("NULLIFY persistence proposition (IS EMPTY) [{}]", e.string()),
                    () -> log.info("NULLIFY persistence proposition (IS NULL)"));
            case PERSIST -> log.info("PERSIST persistence proposition (IS NEW) [{}]", prop.string());
            case REPLACE ->
                    log.info("REPLACE persistence proposition [{}] with asset [{}]", prop.string(), logic.getOutput().string());
            case UNDEFINED -> Optional.ofNullable(prop).ifPresentOrElse(
                    e -> log.info("UNDEFINED persistence proposition [{}]", e.string()),
                    () -> log.info("UNDEFINED persistence proposition (IS NULL)"));
        }
    }
}